﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using PostSharp.Laos;

namespace Lisphi.Lab.PostSharpGettingStart
{
    [Serializable]
    public sealed class TraceAttribute : OnMethodBoundaryAspect 
    { 
        private readonly string category; 

        public TraceAttribute(string category) 
        { 
            this.category = category; 
        } 

        public string Category 
        { 
            get { return category; } 
        }

        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            Trace.WriteLine(string.Format("Entering {0}.{1}.", eventArgs.Method.DeclaringType.Name, eventArgs.Method.Name), this.category);
        }

        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            Trace.WriteLine(string.Format("Leaving {0}.{1}.", eventArgs.Method.DeclaringType.Name, eventArgs.Method.Name), this.category);
        }
    }
}
